
import 'package:demo/swiper.dart';
import 'package:demo/iconItem.dart';
import 'package:demo/newsbox.dart';
import 'package:flutter/material.dart';
import 'package:demo/utils/notify.dart';
import 'dart:io';

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> with AutomaticKeepAliveClientMixin<Home> {
  List<Widget> _createItem(){
    List<Widget> items = [];
    List<Map> titles = [{
      "title":"考勤打卡",
      "icon":"http://42.193.101.147:9000/tlbucket/xjr/20220913/fbc0e7294cc446019184b91358453152.png",
    },
      {
        "title":"OA审批",
        "icon":"http://42.193.101.147:9000/tlbucket/xjr/20220913/fbc0e7294cc446019184b91358453152.png",
      },
      {
        "title":"云盘",
        "icon":"http://42.193.101.147:9000/tlbucket/xjr/20220913/fbc0e7294cc446019184b91358453152.png",
      },
      {
        "title":"会议室",
        "icon":"http://42.193.101.147:9000/tlbucket/xjr/20220913/fbc0e7294cc446019184b91358453152.png"
      },
      {
        "title":"工资条",
        "icon":"http://42.193.101.147:9000/tlbucket/xjr/20220913/fbc0e7294cc446019184b91358453152.png"
      }
    ];
    for (var i=0;i<5;i++){
      Map o = titles[i];
      String title = o['title'];
      String icon = o['icon'];
      items.add(
         GestureDetector(
           child:IconItem(title:title,icon:icon,),
           onTap:(){
             userInfoNotify.setName(title);
           },
         )

      );
    }
    return items;
  }
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return SafeArea(
      bottom:false,
      top:false,
      child:Container(
        width:double.maxFinite,
        color:Color(0xF8F8F8f8),
        child:SingleChildScrollView(child:Column(
          mainAxisAlignment:MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children:[
            Container(
              color:Colors.white,
              width:double.infinity,
              child: Stack(
                children: [
                  Positioned(
                      top:Platform.isIOS?0:-30,
                      child: Container(
                        width:MediaQuery.of(context).size.width,
                        height:200,
                        decoration:const BoxDecoration(
                          color:Colors.white,
                          image:DecorationImage(
                            image:AssetImage("images/bg/topbg.png"),
                            fit:BoxFit.contain,
                          ),
                        ),
                      )
                  ),
                  Container(
                    padding:EdgeInsets.fromLTRB(15, MediaQuery.of(context).padding.top, 15, 15),
                    child: Container(
                      decoration:const BoxDecoration(
                        borderRadius:BorderRadius.all(Radius.circular(10)),
                      ),
                      clipBehavior:Clip.hardEdge,
                      child: WeSwipe(itemCount:4,
                        defaultIndex:0,
                        duration:300,
                        itemBuilder: (int index) {
                          return Container(child:Text("hello ${index}"),padding:const EdgeInsets.all(10),
                            decoration:const BoxDecoration(
                                image:DecorationImage(
                                    fit:BoxFit.cover,
                                    image:AssetImage("images/banner_slices/banner@3x.png")
                                )
                            ),

                          );
                        },
                        width:double.maxFinite,
                        height:150,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Container(
              color:Colors.white,
              child:Wrap(
                children: [
                  ..._createItem(),
                ],),
            ),
            SizedBox(height:12,),
            const NewsBox(),

          ],
        ),
        ),

      ),);
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
